package com.example.knowman.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.knowman.ReturnMessage.*;
import com.example.knowman.dao.knowLabelDetailEx;
import com.example.knowman.dao.knowLabelMainEx;
import com.example.knowman.dao.knowMainEx;
import com.example.knowman.entity.knowLabelMain;
import com.example.knowman.service.IknowLabelDetailService;
import com.example.knowman.service.IknowLabelMainService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//9.2标签
@RestController
@RequestMapping("/knowLabelMain")
public class KnowLabelMainController {
    private final IknowLabelMainService iknowLabelMainService;

    public KnowLabelMainController(IknowLabelMainService iknowLabelMainService) {
        this.iknowLabelMainService = iknowLabelMainService;
    }




//
    @GetMapping("Update")
    public ResponseEntity<Message> update(@RequestParam Integer knowLblId,
                                          @RequestParam(required = false) String lblContent,
                                          @RequestParam(required = false) String notes) {

        Message res = iknowLabelMainService.updateByknowLblId(knowLblId,lblContent,notes);
        if (res.getCode() == 200) {
            return ResponseEntity.ok(res);
        } else {
            return ResponseEntity.badRequest().body(res);
        }
    }

    //根据knowId来显示数据？
    //查
    @GetMapping("getSingle")
    public ResponseEntity<MExKnowLabelMain> getSingle(@RequestParam Integer knowId) {

        knowLabelMain res = iknowLabelMainService.getSingle(knowId);
        MExKnowLabelMain resMessage = new MExKnowLabelMain();
        resMessage.setItem(res);
        resMessage.setCode(200);
        resMessage.setTip("查询成功");
        return ResponseEntity.ok(resMessage);

    }

    //增
    @GetMapping("Insert")
    public ResponseEntity<Message> Insert(@RequestParam Integer knowId,
                                          @RequestParam(required = false) String lblContent,
                                          @RequestParam String staffCode,
                                          @RequestParam(required = false) String notes) {




        Message res = iknowLabelMainService.Insert(knowId,lblContent,staffCode,notes);
        if (res.getCode() == 200) {
            return ResponseEntity.ok(res);
        } else {
            return ResponseEntity.badRequest().body(res);
        }
    }


    //根据knowId返回可供选择的标签lists+所属类别
    @GetMapping("getLabelsByKnowId")
    public ResponseEntity<MessageExKnowLabelMainBackLabels> getLabelsByKnowId(@RequestParam Integer knowId) {

        knowLabelMainEx res = iknowLabelMainService.getLabelsByKnowId(knowId);
        MessageExKnowLabelMainBackLabels resMessage = new MessageExKnowLabelMainBackLabels();
        resMessage.setItem(res);
        resMessage.setCode(200);
        resMessage.setTip("查询成功");
        return ResponseEntity.ok(resMessage);

    }
}
